#!/bin/bash

GVS_START_TIMEKEY="$1"
GVS_END_TIMEKEY="$2"
if [ ${#GVS_START_TIMEKEY} -ne 14 -o ${#GVS_END_TIMEKEY} -ne 14 ] ; then
   echo -e "\n日期参数必须为14位，eg:20200102073000"
   exit 1
fi

S_YYYY=`expr substr $1 1 4`
S_MM=`expr substr $1 5 2`
S_DD=`expr substr $1 7 2`
S_hh=`expr substr $1 9 2`
S_mm=`expr substr $1 11 2`
S_ss=`expr substr $1 13 2`
GVS_START_TIME="${S_YYYY}-${S_MM}-${S_DD} ${S_hh}:${S_mm}:${S_ss}"
date -d "${GVS_START_TIME}" +%Y%m%d%H%M%S > /dev/null
if [ ! $? = 0 ] ; then
   echo -e "\n开始日期不合法，eg:20200101073000"
   exit 1
fi
GVS_START_DATE="${S_YYYY}-${S_MM}-${S_DD}"

E_YYYY=`expr substr $2 1 4`
E_MM=`expr substr $2 5 2`
E_DD=`expr substr $2 7 2`
E_hh=`expr substr $2 9 2`
E_mm=`expr substr $2 11 2`
E_ss=`expr substr $2 13 2`
GVS_END_TIME="${E_YYYY}-${E_MM}-${E_DD} ${E_hh}:${E_mm}:${E_ss}"
date -d "${GVS_END_TIME}" +%Y%m%d%H%M%S > /dev/null
if [ ! $? = 0 ] ; then
   echo -e "\n结束日期不合法，eg:20200102073000"
   exit 1
fi
GVS_END_DATE="${E_YYYY}-${E_MM}-${E_DD}"

S_START_TIME=`date -d "${GVS_START_TIME}" +%s`
S_START_DATE_073000=`date -d "${GVS_START_DATE} 07:30:00" +%s`
S_START_DATE_193000=`date -d "${GVS_START_DATE} 19:30:00" +%s`

if [ ${S_START_TIME} -ge ${S_START_DATE_073000} -a ${S_START_TIME} -lt ${S_START_DATE_193000} ] ; then
   GVS_START_SHIFT_TIMEKEY=`date -d "${GVS_START_TIME}" "+%Y%m%d"`" 073000"
elif [ ${S_START_TIME} -ge ${S_START_DATE_193000} ] ; then
   GVS_START_SHIFT_TIMEKEY=`date -d "${GVS_START_TIME}" "+%Y%m%d"`" 193000"
else
   GVS_START_SHIFT_TIMEKEY=`date -d "-1 day ${GVS_START_TIME}" "+%Y%m%d"`" 193000"
fi
GVS_START_DATE_TIMEKEY=${GVS_START_SHIFT_TIMEKEY:0:8}


S_END_TIME=`date -d "${GVS_END_TIME}" +%s`
S_END_DATE_073000=`date -d "${GVS_END_DATE} 07:30:00" +%s`
S_END_DATE_193000=`date -d "${GVS_END_DATE} 19:30:00" +%s`

if [ ${S_END_TIME} -ge ${S_END_DATE_073000} -a ${S_END_TIME} -lt ${S_END_DATE_193000} ] ; then
   GVS_END_SHIFT_TIMEKEY=`date -d "${GVS_END_TIME}" "+%Y%m%d"`" 073000"
elif [ ${S_END_TIME} -ge ${S_END_DATE_193000} ] ; then
   GVS_END_SHIFT_TIMEKEY=`date -d "${GVS_END_TIME}" "+%Y%m%d"`" 193000"
else
   GVS_END_SHIFT_TIMEKEY=`date -d "-1 day ${GVS_END_TIME}" "+%Y%m%d"`" 193000"
fi
GVS_END_DATE_TIMEKEY=${GVS_END_SHIFT_TIMEKEY:0:8}



GVS_START_HOUR_TIMEKEY=`date -d "-30 minute ${GVS_START_TIME}" "+%Y%m%d %H30"`
GVS_END_HOUR_TIMEKEY=`date -d "-30 minute ${GVS_END_TIME}" "+%Y%m%d %H30"`
GVS_MIN_EVENT_TIMEKEY=${GVS_START_TIMEKEY}